package com.hotel.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 * 类说明
 * 事务管理支持
 */
@Configuration // 标注当前类是一个配置类
@EnableTransactionManagement // 开启事务管理支持
public class MyConfig {

    @Autowired
    private DataSource dataSource;

    // @Bean类似于xml文件中的bean标签
    @Bean  // transactionManager方法名就是bean对象的id
    public DataSourceTransactionManager transactionManager(){
        DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
        transactionManager.setDataSource(dataSource);
        return transactionManager;
    }
}
